<?php
/**
 * 会员卡管理
 * @author tangbl
 *
 */
class VipcardAction extends CommonAction{
	
	/**
	 * 会员卡读卡
	 */
	public function readCard(){
		
		if(IS_AJAX){
		
			$vipno = $this->_param("vipno","trim","");
			
			$map['vipno'] = $vipno;
			$json  = sendRest("MMS/Custom/readCard",$map); 
			$this->ajaxReturn($json);
		}else{
			$this->display();
		}
	}
	
	/**
	 * 会员卡挂失（冻结）
	 */
	public function frost(){
		
		$id = $this->_param("id");
		
		$map['id'] = $id;
		
		$json = sendRest("MMS/Vipcard/frost", $map);
		$this->ajaxReturn($json['data']);
	}
	
	/**
	 * 根据会员级别id，获取自动生成的会员卡号
	 */
	public function getVipno(){
	
		$map['cardid'] = $this->_post('cardid');
		$json = sendRest("MMS/Vipcard/getVipno",$map);
	
		$this->ajaxReturn($json['data']);
	}
	
	/**
	 * 会员卡挂失（解冻）
	 */
	public function thaw(){
		
		$id = $this->_param("id");
		
		$map['id'] = $id;
		
		$json = sendRest("MMS/Vipcard/thaw", $map);
		$this->ajaxReturn($json['data']);
	}
	
	/**
	 * 会员卡换卡
	 */
	public function changeCard(){
		
		if(IS_AJAX){
			
			$json = sendRest("MMS/Vipcard/changeCard",$_POST);
			
			$this->ajaxReturn($json);
		}else{
			
			$id = $this->_param("id","intval",0);
			
			$map['customid'] = $id;
			$json = sendRest("MMS/Custom/view",$map);
			
			$this->assign("detail",$json['data']);
			$this->display();
		}
	}
	
	/**
	 * 储值转账
	 */
	public function transferMoney(){
		
		if(IS_AJAX){
			
			$json = sendRest("MMS/Vipcard/transferMoney",$_POST);
			$this->ajaxReturn($json);
			
		}else{
			$id = $this->_param("id","intval",0);
				
			$map['customid'] = $id;
			$json = sendRest("MMS/Custom/view",$map);
				
			$this->assign("detail",$json['data']);
			$this->display();
		}
		
	}
	
	/**
	 * 积分转账
	 */
	public function transferCredit(){
	
		if(IS_AJAX){
				
			$json = sendRest("MMS/Vipcard/transferCredit",$_POST);
			$this->ajaxReturn($json);
				
		}else{
			$id = $this->_param("id","intval",0);
	
			$map['customid'] = $id;
			$json = sendRest("MMS/Custom/view",$map);
	
			$this->assign("detail",$json['data']);
			$this->display();
		}
	
	}
	
	/**
	 * 重置密码
	 */
	public function reset(){
		
		if(IS_AJAX){
		
			$json = sendRest("MMS/Vipcard/reset",$_POST);
			
			$this->ajaxReturn($json);
		
		}else{
			$id = $this->_param("id","intval",0);
		
			$map['customid'] = $id;
			$json = sendRest("MMS/Custom/view",$map);
		
			$this->assign("detail",$json['data']);
			$this->display();
		}
		
	}
	
	/**
	 * 储值充值
	 */
	public function rechargeMoney(){
		
		if(IS_AJAX){
		
			$json = sendRest("MMS/Vipcard/rechargeMoney",$_POST);
				
			$this->ajaxReturn($json);
		
		}else{
			$id = $this->_param("id","intval",0);
		
			$map['customid'] = $id;
			$json = sendRest("MMS/Custom/view",$map);
		
			$this->assign("detail",$json['data']);
			$this->display();
		}
		
	}
	
	/**
	 * 储值消费
	 */
	public function consumptionMoney(){
	
		if(IS_AJAX){
	
			$json = sendRest("MMS/Vipcard/consumptionMoney",$_POST);
	
			$this->ajaxReturn($json);
	
		}else{
			$id = $this->_param("id","intval",0);
	
			$map['customid'] = $id;
			$json = sendRest("MMS/Custom/view",$map);
	
			$this->assign("detail",$json['data']);
			$this->display();
		}
	
	}
	
	/**
	 * 积分充值
	 */
	public function rechargeCredit(){
	
		if(IS_AJAX){
	
			$json = sendRest("MMS/Vipcard/rechargeCredit",$_POST);
	
			$this->ajaxReturn($json);
	
		}else{
			$id = $this->_param("id","intval",0);
	
			$map['customid'] = $id;
			$json = sendRest("MMS/Custom/view",$map);
	
			$this->assign("detail",$json['data']);
			$this->display();
		}
	
	}
	
	/**
	 * 积分消费
	 */
	public function consumptionCredit(){
	
		if(IS_AJAX){
	
			$json = sendRest("MMS/Vipcard/consumptionCredit",$_POST);
	
			$this->ajaxReturn($json);
	
		}else{
			$id = $this->_param("id","intval",0);
	
			$map['customid'] = $id;
			$json = sendRest("MMS/Custom/view",$map);
	
			$this->assign("detail",$json['data']);
			$this->display();
		}
	
	}
	
	/**
	 * 赠送积分(批量)
	 */
	public function getIntegral(){
	
		if(IS_AJAX){
			
			$json = sendRest("MMS/Vipcard/getIntegral",$_POST);
			$this->ajaxReturn($json);
			
		}else{
				
			$val = $this->_param("val","trim","");
			$arr = explode(',',$val);

			if($val){
				$this->assign("str","是否对当前选中的会员（".count($arr)."个）赠送积分？");
			}else{
				$this->assign("str","是否对 【所有会员】 的会员赠送积分？");
			}
			
			$this->assign("val",$val);
			$this->display();
		}
	}
	
	/**
	 * 积分清零
	 * 
	 */
	public function clearIntegral(){
		
		$map['val'] = $this->_param("val","trim","");
		
		$json = sendRest("MMS/Vipcard/clearIntegral",$map);
		
		$this->ajaxReturn($json);
	}
	
	/**
	 * 储值清零
	 *
	 */
	public function clearMoney(){
	
		$map['val'] = $this->_param("val","trim","");
	
		$json = sendRest("MMS/Vipcard/clearMoney",$map);
	
		$this->ajaxReturn($json);
	}
	
	/**
	 * 赠送储值
	 */
	public function getMoney(){
	
		if(IS_AJAX){
				
			$json = sendRest("MMS/Vipcard/getMoney",$_POST);
			$this->ajaxReturn($json);
				
		}else{
	
			$val = $this->_param("val","trim","");
			$arr = explode(',',$val);
	
			if($val){
				$this->assign("str","是否对当前选中的会员（".count($arr)."个）赠送储值？");
			}else{
				$this->assign("str","是否对 【所有会员】 的会员赠送储值？");
			}
				
			$this->assign("val",$val);
			$this->display();
		}
	}
		
}
